package com.dkd.app.common.core;

import java.util.HashMap;
import java.util.Map;

public class AjaxResult {
    private int code;
    private String msg;
    private Map<String, Object> data = new HashMap<>();

    // 成功时的静态方法
    public static AjaxResult success() {
        return setResult(200, "操作成功");
    }

    // 失败时的静态方法
    public static AjaxResult error(String msg) {
        return setResult(500, msg);
    }

    private static AjaxResult setResult(int code, String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    // 添加数据到结果中
    public AjaxResult put(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    // Getter 和 Setter 方法
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }
}